const BASE_URL = "http://localhost:3000";
interface dataType{
    data:object
}
class Request {
    //下面method就是字符串字面量类型 原来这么用(.
    request<T>(url:string,method:"OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | undefined, data:any):Promise<T>{
    return new Promise((resolve, reject) => {
        wx.request({
        url: BASE_URL + url, 
        data,
        method,
        header: {
          "content-type": "application/json", // 默认值
        },
        success(res:any){
            resolve(res.data.data);
        },
        fail(err) {
            reject(err);
        },
    });
    });
} 
    get<T>(url:string,data:object):Promise<T>{
        return  this.request(url,'GET',data)
    }
    post<T>(url:string,data:object):Promise<T>{
        return  this.request(url,'POST',data)
    }

}

export const request=new Request()

